//As the call stack is unwound, the destructor for the constructed local 
//object are invoked
//
//Resource acquisition is initialization
#include <iostream>
using namespace std;

class A {
  int aa;
public:
  A(){cout<<"A()"<<endl;}
  ~A(){cout<<"~A()"<<endl;}
};

void foo()
{
  A a;
  try {
    int i = 12;
    throw i;
  }
  catch(int j){
    cout<<"catch in foo()"<<endl;
    cout<<"j ="<<j<<endl;
    throw j;
  }

  cout<<"out of try-catch"<<endl;
}

int main()
{
  try{
    foo();
  }
  catch(int) {
    cout<<"catch in main()"<<endl;
  }
  cout<<"out of catch in main()"<<endl;
  return 0;
}
    
